#!/bin/bash

# ==================================================================
#  Stable Video Diffusion (SVD) 一键部署脚本 (For Linux)
# ==================================================================

# 如果任何命令失败，则立即退出
set -e

echo ""
echo "[INFO] 开始 Stable Video Diffusion 部署流程..."
echo ""

# --- 检查虚拟环境 ---
if [ ! -d "svd_env" ]; then
    echo "[INFO] 未检测到虚拟环境，正在创建..."
    python3 -m venv svd_env
fi

echo "[INFO] 激活虚拟环境..."
. svd_env/bin/activate

# --- 步骤 1: 环境配置和依赖安装 ---
echo ""
echo "[STEP 1/3] 正在配置环境并安装依赖包..."
python setup_environment.py
echo "[SUCCESS] 环境配置成功！"


# --- 步骤 2: 下载模型 ---
echo ""
echo "[STEP 2/3] 正在下载模型文件..."
python download_models.py
echo "[SUCCESS] 模型下载成功！"


# --- 步骤 3: 启动服务 ---
echo ""
echo "[STEP 3/3] 正在启动推理服务..."
echo ""
echo "###############################################################"
echo ""
echo "  服务正在启动，请在浏览器或API工具中访问:"
echo "  http://<your-server-ip>:8080"
echo ""
echo "  健康检查URL: http://<your-server-ip>:8080/health"
echo ""
echo "  按 CTRL+C 停止服务"
echo ""
echo "###############################################################"
echo ""
python svd_server.py


echo ""
echo "[INFO] 脚本执行完毕。"

